
<%@ page import="br.unicarioca.viaexpositus.Permissao" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'permissao.label', default: 'Permissao')}" />
        <title><g:message code="default.edit.label" args="[entityName]" /></title>
        <script src="${resource(dir:'js/prototype',file:'prototype.js')}" type='text/javascript'></script>
    </head>
    <body>

        <div class="body">
            <div>
            	<h1><g:message code="default.edit.label" args="[entityName]" /></h1>
		        <div class="buttonsBar">
		            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
		            <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
		        </div>
		        <div class="clear"></div>
	    	</div>

            <div class="clear" >&nbsp;</div>

            <g:if test="${flash.message}">
                <div class="message">${flash.message}</div>
            </g:if>

            <g:hasErrors bean="${permissaoInstance}">
                <div class="errors">
                    <g:renderErrors bean="${permissaoInstance}" as="list" />
                </div>
            </g:hasErrors>

            <g:form method="post" >
                <div class="dialog">
	                <g:hiddenField name="id" value="${permissaoInstance?.id}" />
	                <g:hiddenField name="version" value="${permissaoInstance?.version}" />
                    <div>
                      <%mapa.each{ controle, listaAcoes -> %>
                          <div>
                            <div>Controle: ${controle}</div>
                            <div>
                                <%listaAcoes.each{ acao, nome -> %>
                                  <div> -------------- Ação: ${acao} --> Nome: ${nome}</div>
                                <%}%>
                            </div>
                          </div>
                      <%}%>
                    </div>
                    <table>
                        <tbody>

                            <script>
                              function buscarAcoes(obj){
                                  alert("obj = "+obj.value)
                                  new Ajax.Updater('updateHere','${createLink(controller:"permissao", action:"atualizarCombo")}',
                                  {asynchronous:false,evalScripts:true,parameters:'controle='+obj.value});
                              }
                            </script>

                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="controle">Controle</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: permissaoInstance, field: 'url', 'errors')}">
                                    <g:select name="controle" from="${mapa*.key}" value="${permissaoInstance?.perfil}"  onchange="buscarAcoes(this)"/>
                                    <div id="updateHere">
                                    </div>
                                </td>
                            </tr>
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="url"><g:message code="permissao.codigo.label" default="Url" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: permissaoInstance, field: 'url', 'errors')}">
                                    <g:textField name="url" value="${permissaoInstance?.url}" />
                                </td>
                            </tr>
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="perfil"><g:message code="permissao.perfil.label" default="Perfil" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: permissaoInstance, field: 'perfil', 'errors')}">
                                    <g:select name="perfil" from="${br.unicarioca.viaexpositus.Perfil.list()}" optionKey="codenome" value="${permissaoInstance?.perfil}"  />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                	<g:if test="${permissaoInstance?.id}">
                    	<span class="button"><g:actionSubmit class="save" action="update" value="${message(code: 'default.button.save.label', default: 'Save')}" /></span>
                    </g:if>
                    <g:else>
                    	<span class="button"><g:actionSubmit class="save" action="save" value="${message(code: 'default.button.save.label', default: 'Save')}" /></span>
                    </g:else>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" /></span>
                </div>
            </g:form>
        </div>
    </body>
</html>
